/**
 * Copyright (c) 2017-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 *
 * @flow strict
 * @format
 */

export function destroyItemWhere(
  predicate: (item: atom$PaneItem) => boolean,
): Promise<Array<boolean>> {
  const destroyItemStatuses = [];
  atom.workspace.getPanes().forEach(pane => {
    pane.getItems().forEach(item => {
      if (predicate(item)) {
        destroyItemStatuses.push(pane.destroyItem(item, true));
      }
    });
  });
  return Promise.all(destroyItemStatuses);
}
